﻿using ConnectDatabase;
using Database;
using Galileo;
using IBE;
using IBE.GalileoLccService;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace Web
{
    public partial class Result : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["SearchCondition"]))
                {
                    List<FareData> listData = new List<FareData>();
                    if (Session[Request.QueryString["SearchCondition"]] != null)
                    {
                        listData = (List<FareData>)Session[Request.QueryString["SearchCondition"]];
                        if (listData.Count == 0)
                        {
                            string responseFile = GetResponseFile();
                            listData = GetListDataFromResponseFile(responseFile);
                            Session[Request.QueryString["SearchCondition"]] = listData;
                        }
                    }
                    else
                    {
                        string responseFile = GetResponseFile();
                        listData = GetListDataFromResponseFile(responseFile);
                        Session[Request.QueryString["SearchCondition"]] = listData;
                    }

                    if (listData != null && listData.Count > 0)
                    {
                        InitAirlineFilter(listData);
                        FillData(listData);
                    }
                    else
                    {
                        Response.Redirect("~/Error.aspx", false);
                    }
                }
            }
        }

        protected tblFlightSearchArchive GetSearchConditionFromSession()
        {
            tblFlightSearchArchive obj = null;
            try
            {
                Common utility = new Common();

                if (!string.IsNullOrEmpty(Request.QueryString["SearchCondition"]))
                {
                    string searchCondition = Request.QueryString["SearchCondition"];
                    obj = new tblFlightSearchArchive();

                    if (Session[searchCondition + "Departure"] != null)
                    {
                        obj.DepartureAirportCode = Session[searchCondition + "Departure"].ToString();
                    }
                    else
                    {
                        return null;
                    }

                    if (Session[searchCondition + "Destination"] != null)
                    {
                        obj.DestinationAirportCode = Session[searchCondition + "Destination"].ToString();
                    }
                    else
                    {
                        return null;
                    }

                    if (Session[searchCondition + "DepartureDate"] != null)
                    {
                        obj.DepartureDate = utility.GetDateFormat(Session[searchCondition + "DepartureDate"].ToString(), "dd/MM/yyyy");
                    }
                    else
                    {
                        return null;
                    }

                    if (Session[searchCondition + "ReturnDate"] != null)
                    {
                        obj.ReturnDate = utility.GetDateFormat(Session[searchCondition + "ReturnDate"].ToString(), "dd/MM/yyyy");
                    }
                    else
                    {
                        return null;
                    }

                    if (Session[searchCondition + "Adt"] != null)
                    {
                        obj.Adult = Convert.ToInt16(Session[searchCondition + "Adt"].ToString());
                    }
                    else
                    {
                        return null;
                    }

                    if (Session[searchCondition + "Chd"] != null)
                    {
                        obj.Children = Convert.ToInt16(Session[searchCondition + "Chd"].ToString());
                    }
                    else
                    {
                        return null;
                    }

                    if (Session[searchCondition + "Inf"] != null)
                    {
                        obj.Infant = Convert.ToInt16(Session[searchCondition + "Inf"].ToString());
                    }
                    else
                    {
                        return null;
                    }

                    if (Session[searchCondition + "ItineraryType"] != null)
                    {
                        obj.ItineraryType = Convert.ToBoolean(Session[searchCondition + "ItineraryType"].ToString());
                    }
                    else
                    {
                        return null;
                    }

                    obj.Youth = 0;
                    obj.Senior = 0;
                }
            }
            catch
            {
                Response.Redirect("~/Error.aspx", false);
            }
            return obj;
        }

        protected tblFlightSearchArchive GetExistedSearchWithIn10Minutes(tblFlightSearchArchive newSearch)
        {
            //Tạm thời bỏ cache
            //tblFlightSearchArchive obj = new FlightSearchArchiveDB().GetExistedSearch(newSearch);
            //if (obj != null)
            //{
            //    double difference = DateTime.Now.Subtract(obj.Date.Value).TotalMinutes;
            //    if (difference > 10)
            //    {
            //        obj = null;
            //    }
            //}

            //return obj;
            return null;
        }

        protected string GetResponseFile()
        {
            string responseFile = "";
            tblFlightSearchArchive newSearch = GetSearchConditionFromSession(); //Lấy đối tượng tblSearchArchive từ Session
            if (newSearch != null)
            {
                tblFlightSearchArchive existedSearch = GetExistedSearchWithIn10Minutes(newSearch); //Kiểm tra sự tồn tại của tìm kiếm đồng dạng trước đó 10 phút
                if (existedSearch != null)
                {
                    //Nếu đã tồn tại một tìm kiếm đồng dạng trong vòng 10 phút thì lôi nó ra
                    responseFile = existedSearch.Result;
                    hdhSearchArchiveId.Value = existedSearch.Id.ToString();
                }
                else
                {
                    //Nếu không tồn tại một tìm kiếm đồng dạng trong vòng 10 phút thì thực hiện tìm kiếm mới
                    responseFile = RequestFlight(newSearch);
                    Session[Request.QueryString["SearchCondition"]] = null;
                }
            }
            else
            {
                Response.Redirect("~/Error.aspx", false);
            }
            return responseFile;
        }

        protected List<FareData> GetListDataFromResponseFile(string fileName)
        {
            List<FareData> listData = new List<FareData>();
            try
            {
                #region GDS
                FileInfo file = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "/Response/" + fileName);
                if (file != null && file.Exists)
                {
                    //Nếu tồn tại file XmlResponse thì bóc tách
                    XmlDocument xml = new XmlDocument();
                    try
                    {
                        xml.Load(AppDomain.CurrentDomain.BaseDirectory + "/Response/" + fileName);
                    }
                    catch
                    {

                    }
                    GDSParser parser = new GDSParser();
                    listData = parser.FilterData(parser.GetFareData(xml));
                }
                else
                {
                    //Nếu không tồn tại file XmlResponse thì tiến hành Request tìm kiếm mới
                    tblFlightSearchArchive newSearch = GetSearchConditionFromSession();
                    if (newSearch != null)
                    {
                        string responseFile = RequestFlight(newSearch);
                        if (responseFile != "")
                        {
                            Session[Request.QueryString["SearchCondition"]] = null;
                            XmlDocument xml = new XmlDocument();
                            try
                            {
                                xml.Load(AppDomain.CurrentDomain.BaseDirectory + "/Response/" + responseFile);
                            }
                            catch
                            {

                            }
                            GDSParser parser = new GDSParser();
                            listData = parser.GetFareData(xml);
                        }
                    }
                }
                #endregion

                #region LCC
                if (Session[Request.QueryString["SearchCondition"] + "Lcc"] != null)
                {
                    List<FareData> listLccData = new List<FareData>();
                    List<Repository> lccResponse = (List<Repository>)Session[Request.QueryString["SearchCondition"] + "Lcc"];
                    LowcostParser service = new LowcostParser();
                    listLccData = service.GetLowcostFareDataFlexible(lccResponse);

                    foreach (FareData item in listLccData)
                    {
                        listData.Add(item);
                    }
                }
                #endregion

                //Re-index fare data ID
                int fareDataId = 0;
                for (int i = 0; i < listData.Count; i++)
                {
                    listData[i].FareDataId = fareDataId;
                    for (int j = 0; j < listData[i].ListDepartureFlight.Count; j++)
                    {
                        listData[i].ListDepartureFlight[j].FareDataId = fareDataId;
                    }

                    if (listData[i].ListReturnFlight != null)
                    {
                        for (int j = 0; j < listData[i].ListReturnFlight.Count; j++)
                        {
                            listData[i].ListReturnFlight[j].FareDataId = fareDataId;
                        }
                    }
                    fareDataId++;
                }

                Session[Request.QueryString["SearchCondition"]] = listData;
            }
            catch
            {
                Response.Redirect("~/Error.aspx", false);
            }
            return listData;
        }

        protected string RequestFlight(tblFlightSearchArchive searchCondition)
        {
            //Hàm này thực hiện request tìm kiếm từ GDS và LCC web service
            string responseFile = "";
            try
            {
                GDSParser parser = new GDSParser();
                responseFile = searchCondition.ItineraryType.Value ? parser.GenerateResponseSearchKey(searchCondition, true) : parser.GenerateResponseSearchKey(searchCondition, false);

                #region GDS
                Thread threadGDS = null;
                threadGDS = new Thread(() =>
                {
                    XmlDocument xmlResponse = new XmlDocument();
                    GalileoConnection conn = new GalileoConnection();

                    string default_api = ConfigurationManager.AppSettings["default_api"].ToString();
                    string hcm_pcc = ConfigurationManager.AppSettings["hcm_pcc"].ToString();
                    string hcm_name = ConfigurationManager.AppSettings["hcm_name"].ToString();

                    string xmlRequest = searchCondition.ItineraryType.Value ? parser.GenerateXmlRequest(searchCondition, true) : parser.GenerateXmlRequest(searchCondition, false);

                    string strResponse = conn.SubmitXml(xmlRequest, default_api, hcm_pcc, hcm_name);
                    if (strResponse != "")
                    {
                        try
                        {
                            xmlResponse.LoadXml(strResponse);
                        }
                        catch (Exception)
                        {

                        }
                    }

                    //Save to Xml files
                    string appPath = AppDomain.CurrentDomain.BaseDirectory;
                    FileInfo fileInfo = new FileInfo(appPath + "/Response/" + responseFile);
                    if (fileInfo != null)
                    {
                        File.Delete(appPath + "/Response/" + responseFile);
                    }

                    Common.SaveFile(appPath + "/Response/" + responseFile, xmlResponse.InnerXml);
                });
                threadGDS.Start();
                #endregion

                #region Lcc
                HttpContext context = HttpContext.Current;
                Thread threadLCC = null;
                threadLCC = new Thread(() =>
                {
                    AirlineServices service = new AirlineServices();
                    //Khai báo tham số cho LCC web service
                    service.AuthenticationValue = new Authentication { Username = "lccservice", Password = "Wfd@!9438DSbvh" };
                    string agentSignOn = "vietanhanoi@gmail.com";
                    string agentPassword = "123456";
                    int itineraryType = searchCondition.ItineraryType.Value ? 1 : 0; //1 là one way, 0 là round trip
                    string departure = searchCondition.DepartureAirportCode;
                    string destination = searchCondition.DestinationAirportCode;
                    string departureDate = searchCondition.DepartureDate.Value.ToString("dd/MM/yyyy");
                    string returnDate = searchCondition.ReturnDate != null ? searchCondition.ReturnDate.Value.ToString("dd/MM/yyyy") : DateTime.Now.ToString("dd/MM/yyyy");
                    string ADT = searchCondition.Adult.ToString();
                    string CHD = searchCondition.Children.ToString();
                    string INF = searchCondition.Infant.ToString();

                    List<LccInfo> lstLccInfo = new List<LccInfo>();
                    lstLccInfo.Add(new LccInfo { AirlineCode = "VN", AllowSearch = true, LoginLccUser = "", LoginLccPassword = "" });
                    lstLccInfo.Add(new LccInfo { AirlineCode = "JQ", AllowSearch = true, LoginLccUser = "WEB", LoginLccPassword = "Vietan@99" });
                    lstLccInfo.Add(new LccInfo { AirlineCode = "VJ", AllowSearch = true, LoginLccUser = "AG39038233", LoginLccPassword = "Vietan@99" });

                    Repository[] lccResponse = service.FlightSearchFlexible(agentSignOn, agentPassword, lstLccInfo.ToArray(), itineraryType, departure, destination, departureDate, returnDate, ADT, CHD, INF);

                    List<Repository> listRepository = new List<Repository>();
                    if (lccResponse != null)
                    {
                        for (int i = 0; i < lccResponse.Length; i++)
                        {
                            listRepository.Add(lccResponse[i]);
                        }

                        Session[Request.QueryString["SearchCondition"] + "Lcc"] = listRepository;
                    }
                });
                threadLCC.Start();
                #endregion

                if (threadGDS != null) threadGDS.Join();
                if (threadLCC != null) threadLCC.Join();

                //Save this search
                searchCondition.Date = DateTime.Now;
                searchCondition.Result = responseFile;
                if (Session["UserID"] != null)
                {
                    searchCondition.AccountId = Convert.ToInt32(Session["UserID"]);
                }
                hdhSearchArchiveId.Value = new FlightSearchArchiveDB().Insert(searchCondition).ToString();
            }
            catch
            {
                Response.Redirect("~/Error.aspx", false);
            }

            return responseFile;
        }

        protected void FillData(List<FareData> listData)
        {
            List<FareData> newListData = listData;

            #region Sorting
            if (hdhSortStatus.Value == "0")
            {
                if (hdhSortValue.Value == "Price")
                {
                    //newListData = listData.OrderBy(x => clsBSUtility.getConvertedCurrencyValue(x.TotalFare, x.CurrencyCode, Session["currency"].ToString())).ToList();
                    newListData = listData.OrderBy(x => x.TotalFare).ToList();
                }
                else if (hdhSortValue.Value == "FlightDuration")
                {
                    newListData = listData.OrderBy(x => x.TotalDuration).ToList();
                }
                else if (hdhSortValue.Value == "DepartureTime")
                {
                    newListData = listData.OrderBy(x => x.DepartureDate).ToList();
                }
                else if (hdhSortValue.Value == "ReturnTime")
                {
                    newListData = listData.OrderBy(x => x.ReturnDate).ToList();
                }
            }
            else
            {
                if (hdhSortValue.Value == "Price")
                {
                    //newListData = listData.OrderByDescending(x => clsBSUtility.getConvertedCurrencyValue(x.TotalFare, x.CurrencyCode, Session["currency"].ToString())).ToList();
                    newListData = listData.OrderByDescending(x => x.TotalFare).ToList();
                }
                else if (hdhSortValue.Value == "FlightDuration")
                {
                    newListData = listData.OrderByDescending(x => x.TotalDuration).ToList();
                }
                else if (hdhSortValue.Value == "DepartureTime")
                {
                    newListData = listData.OrderByDescending(x => x.DepartureDate).ToList();
                }
                else if (hdhSortValue.Value == "ReturnTime")
                {
                    newListData = listData.OrderByDescending(x => x.ReturnDate).ToList();
                }
            }


            #endregion

            #region Paging
            PagedDataSource pgitems = new PagedDataSource();
            pgitems.DataSource = newListData;
            pgitems.AllowPaging = true;
            pgitems.PageSize = 10;
            int index = Convert.ToInt16(hdnPageIndex.Value);
            pgitems.CurrentPageIndex = index;
            if (pgitems.PageCount > 1)
            {
                repPages.Visible = true;
                System.Collections.ArrayList pages = new System.Collections.ArrayList();
                for (int i = 0; i < pgitems.PageCount; i++)
                {
                    pages.Add((i + 1).ToString());
                }
                repPages.DataSource = pages;
                repPages.DataBind();
            }
            else
            {
                repPages.Visible = false;
            }

            if (pgitems != null)
            {
                repFilght.DataSource = pgitems;
                repFilght.DataBind();
            }

            if (pgitems.PageCount > 1)
            {
                RepeaterItem item = repPages.Items[index];
                LinkButton link = (LinkButton)item.FindControl("btnPage");
                link.Enabled = false;
                link.CssClass = "visited";
            }
            #endregion

            if (newListData.Count > 0)
            {
                repFilght.Visible = true;
                //EmptyItem.Visible = false;
            }
            else
            {
                repFilght.Visible = false;
                //EmptyItem.Visible = true;
            }

            newListData = null;
        }

        protected void FilterFareData()
        {
            try
            {
                List<FareData> listData = new List<FareData>();
                if (Session[Request.QueryString["SearchCondition"]] != null)
                {
                    listData = (List<FareData>)Session[Request.QueryString["SearchCondition"]];
                }
                else
                {
                    string responseFile = GetResponseFile();
                    listData = GetListDataFromResponseFile(responseFile);
                }

                List<FareData> newList = new List<FareData>();
                foreach (FareData item in listData)
                {
                    newList.Add(item.ShallowCopy());
                }

                //RadSlider sliderFlightTime = (RadSlider)FilterPanelBar.FindItemByValue("TotalFlightTime").FindControl("sliderFlightTime");
                //RadSlider sliderPrice = (RadSlider)FilterPanelBar.FindItemByValue("PriceFilter").FindControl("sliderPrice");

                foreach (FareData fare in newList)
                {
                    #region Departure
                    //Filter by stop points
                    var filtered = from a in fare.ListDepartureFlight
                                   where ((!ckbDirectFlight.Checked) ? a.StopNum != 0 : true)
                                    && ((!ckbOneStop.Checked) ? a.StopNum != 1 : true)
                                    && ((!ckbTwoStop.Checked) ? a.StopNum != 2 : true)
                                    && ((!ckbThreeStop.Checked) ? a.StopNum != 3 : true)
                                    //&& a.Duration.TotalMinutes <= (Convert.ToDouble(sliderFlightTime.Value))
                                   select a;
                    fare.ListDepartureFlight = filtered.ToList();

                    //Filter by airlines
                    for (int i = 0; i < ckbListAirline.Items.Count; i++)
                    {
                        if (!ckbListAirline.Items[i].Selected)
                        {
                            filtered = from a in fare.ListDepartureFlight
                                       where !a.AirlineDetail.Code.Equals(ckbListAirline.Items[i].Value)
                                       select a;
                            fare.ListDepartureFlight = filtered.ToList();
                        }
                    }
                    #endregion

                    #region Return
                    if (fare.HasReturn)
                    {
                        //Filter by stop points
                        filtered = from a in fare.ListReturnFlight
                                   where ((!ckbDirectFlight.Checked) ? a.StopNum != 0 : true)
                                    && ((!ckbOneStop.Checked) ? a.StopNum != 1 : true)
                                    && ((!ckbTwoStop.Checked) ? a.StopNum != 2 : true)
                                    && ((!ckbThreeStop.Checked) ? a.StopNum != 3 : true)
                                    //&& a.Duration.TotalMinutes <= (Convert.ToDouble(sliderFlightTime.Value))
                                   select a;
                        fare.ListReturnFlight = filtered.ToList();

                        //Filter by airlines
                        for (int i = 0; i < ckbListAirline.Items.Count; i++)
                        {
                            if (!ckbListAirline.Items[i].Selected)
                            {
                                filtered = from a in fare.ListReturnFlight
                                           where !a.AirlineDetail.Code.Equals(ckbListAirline.Items[i].Value)
                                           select a;
                                fare.ListReturnFlight = filtered.ToList();
                            }
                        }
                    }
                    #endregion
                }

                newList = (from a in newList
                           where a.ListDepartureFlight.Count > 0 && ((a.HasReturn) ? a.ListReturnFlight.Count > 0 : true)
                           //&& clsBSUtility.getConvertedCurrencyValue(Convert.ToDecimal(a.TotalFare), a.CurrencyCode, Session["currency"].ToString()) <= (sliderPrice.Value)
                           select a).ToList();

                if (newList.Count <= 10)
                {
                    hdnPageIndex.Value = "0";
                }
                else
                {
                    int numberOfPages = (newList.Count / 10) + (newList.Count % 10 == 0 ? 0 : 1);
                    int index = Convert.ToInt16(hdnPageIndex.Value);
                    if (index + 1 > numberOfPages)
                    {
                        hdnPageIndex.Value = "0";
                    }
                }

                FillData(newList);
                //RadAjaxManager1.ResponseScripts.Add("ScrollToControl()");
            }
            catch
            {
                Response.Redirect("~/Error.aspx", false);
            }
        }

        protected void repFilght_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            try
            {
                if (e.CommandName.Equals("Continue"))
                {
                    string id = e.CommandArgument.ToString();
                    string url = "";

                    string FareInputControlName = "FareItem" + id;
                    string DepartureInputControlName = "DepartureFlightValue" + id;
                    string ReturnInputControlName = "ReturnFlightValue" + id;
                    string HasReturnInputControlName = "HasReturn" + id;

                    string FareDataId = Request.Form[FareInputControlName].ToString();
                    string DepartureId = Request.Form[DepartureInputControlName].ToString();
                    string ReturnId = Request.Form[ReturnInputControlName].ToString();

                    string SelectedValue = FareDataId + "-" + DepartureId + "-" + ReturnId;

                    url = "~/Book.aspx?&Search=" + Request.QueryString["SearchCondition"] + "&SelectedValue=" + SelectedValue;

                    Session[Request.QueryString["SearchCondition"] + SelectedValue + "FareDataId"] = FareDataId;
                    Session[Request.QueryString["SearchCondition"] + SelectedValue + "DepartureId"] = DepartureId;
                    Session[Request.QueryString["SearchCondition"] + SelectedValue + "ReturnId"] = ReturnId;

                    List<FareData> listData = (List<FareData>)Session[Request.QueryString["SearchCondition"]];
                    if (listData == null)
                    {
                        //Nếu Session == null thì lấy listData từ file
                        string responseFile = GetResponseFile();
                        listData = GetListDataFromResponseFile(responseFile);
                    }
                    FareData temp = listData.FirstOrDefault(a => a.FareDataId == Convert.ToInt32(FareDataId));
                    Session[Request.QueryString["SearchCondition"] + SelectedValue] = temp;
                    Response.Redirect(url, false);
                }
            }
            catch
            {
                
            }
        }

        protected void repPages_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            hdnPageIndex.Value = (Convert.ToInt32(e.CommandArgument) - 1).ToString();
            FilterFareData();
        }

        #region Sorting
        protected void lnkSortPrice_Click(object sender, EventArgs e)
        {
            SortingFlight(lnkSortPrice, "Price");
        }

        protected void lnkSortFlightDuration_Click(object sender, EventArgs e)
        {
            SortingFlight(lnkSortFlightDuration, "FlightDuration");
        }

        protected void lnkSortDepartureTime_Click(object sender, EventArgs e)
        {
            SortingFlight(lnkSortDepartureTime, "DepartureTime");
        }

        protected void lnkSortReturnTime_Click(object sender, EventArgs e)
        {
            SortingFlight(lnkSortReturnTime, "ReturnTime");
        }

        protected void ResetSortStyle()
        {
            lnkSortPrice.CssClass = "SortLink";
            lnkSortFlightDuration.CssClass = "SortLink";
            lnkSortDepartureTime.CssClass = "SortLink";
            lnkSortReturnTime.CssClass = "SortLink";
        }

        protected void SetSortStyle(LinkButton control, string cssClass)
        {
            ResetSortStyle();
            control.CssClass = "SortLink " + cssClass;
        }

        protected void SortingFlight(LinkButton control, string comparison)
        {
            if (hdhSortStatus.Value == "1")
            {
                hdhSortValue.Value = comparison;
                hdhSortStatus.Value = "0";
                SetSortStyle(control, "Ascending");
            }
            else
            {
                hdhSortValue.Value = comparison;
                hdhSortStatus.Value = "1";
                SetSortStyle(control, "Descending");
            }

            FilterFareData();
        }
        #endregion

        #region Filter
        protected void ckbDirectFlight_CheckedChanged(object sender, EventArgs e)
        {
            FilterFareData();
        }

        protected void ckbOneStop_CheckedChanged(object sender, EventArgs e)
        {
            FilterFareData();
        }

        protected void ckbTwoStop_CheckedChanged(object sender, EventArgs e)
        {
            FilterFareData();
        }

        protected void ckbThreeStop_CheckedChanged(object sender, EventArgs e)
        {
            FilterFareData();
        }

        protected void InitAirlineFilter(List<FareData> listData)
        {
            var obj = from a in listData
                      from b in a.ListDepartureFlight
                      group b.AirlineDetail by b.AirlineDetail.Code into g
                      select g.First();
            List<tblAirline> listAirline = obj.ToList();

            try
            {
                obj = from a in listData
                      from b in a.ListReturnFlight
                      group b.AirlineDetail by b.AirlineDetail.Code into g
                      select g.First();

                List<tblAirline> listAirlineReturn = obj.ToList();
                foreach (tblAirline item in listAirlineReturn)
                {
                    listAirline.Add(item);
                }

                obj = from a in listAirline
                      group a by a.Code into g
                      select g.First();
                listAirline = obj.ToList();
            }
            catch
            {
                obj = from a in listAirline
                      group a by a.Code into g
                      select g.First();
                listAirline = obj.ToList();
            }

            ckbListAirline.Items.Clear();
            foreach (tblAirline airline in listAirline)
            {
                ListItem item = new ListItem();
                item.Value = airline.Code;
                item.Text = airline.Name_Vi;
                item.Selected = true;
                ckbListAirline.Items.Add(item);
            }
        }

        protected void ckbListAirline_SelectedIndexChanged(object sender, EventArgs e)
        {
            FilterFareData();
        }

        #endregion
    }
}